package com.billing.web.controller.compensation;

import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.billing.model.entity.AttendanceBean;
import com.billing.model.entity.EarlyBean;
import com.billing.model.entity.LateBean;
import com.billing.model.entity.OvertimeBean;
import com.billing.model.entity.TAttendance;
import com.billing.model.entity.TIndividualTaxFormula;
import com.billing.model.entity.TLatedeductions;
import com.billing.model.entity.TMaindata;
import com.billing.model.entity.TSubsidy;
import com.billing.model.entity.TUser;
import com.billing.model.entity.TUserPay;
import com.billing.model.entity.TUserPayReport;
import com.billing.model.entity.TUserPayReportList;
import com.billing.model.entity.UserBean;
import com.billing.model.entity.UserPayReportAppBean;
import com.billing.service.AnnualBonusService;
import com.billing.service.AttendanceService;
import com.billing.service.IndividualTaxFormulaService;
import com.billing.service.LatedeductionsService;
import com.billing.service.MaindataService;
import com.billing.service.PerformanceService;
import com.billing.service.SubsidyService;
import com.billing.service.UserBeanService;
import com.billing.service.UserPayReportService;
import com.billing.service.UserPayService;
import com.billing.service.UserService;
import com.billing.utils.DateUtil;
import com.billing.utils.ExcelUtil;


/**
 * 薪酬报表
 * @author Administrator
 *
 */
@RequestMapping(value="/remuneration")
@Controller
public class RemunerationReportController {

	@Resource
	private UserPayReportService userPayReportService; 
	@Resource
	private LatedeductionsService latedeductionsService;
	@Resource
	private UserBeanService userBeanService;
	@Resource
	private AttendanceService attendanceService;
	@Resource
	private MaindataService maindataService;
	@Resource
	private UserPayService userPayService; 
	@Resource
	private UserService userService;
	@Resource
	private IndividualTaxFormulaService individualTaxFormulaService;
	@Resource
	private AnnualBonusService annualBonusService;
	@Resource
	private SubsidyService  subsidyService;
	@Resource
	private PerformanceService performanceService;
	
	
	/**
	 * 获取薪酬报表信息
	 * @param request
	 * @param model
	 * @return
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index(HttpServletRequest request, Model model) throws IllegalAccessException, InvocationTargetException{
		String time=request.getParameter("time");
		String name=request.getParameter("name");
		String jobnumber=request.getParameter("jobnumber");
		int organizationid=(int) request.getSession().getAttribute("organizationid");
		int year=0;
		int month=0;
		if(time!=null&&time!=""){
			if(time.lastIndexOf("-")>-1){
				year=Integer.valueOf(time.substring(0,time.lastIndexOf("-")));
				month=Integer.valueOf(time.substring(time.lastIndexOf("-")+1, time.length()));
			}
			int pageSize = 10;
			// 获取当前页数
			int currentPage = 1;
			try {
				currentPage = new Integer(request.getParameter("currentPage"));
			} catch (Exception e) {
			}
			currentPage = currentPage <= 0 ? 1 : currentPage;
			int totalNum = userPayReportService.getTUserPayReportNum(year, month, name, jobnumber,organizationid);
			int totalPage = totalNum / pageSize;
			if (totalNum % pageSize != 0) {
				totalPage++;
			}
			totalPage = totalPage <= 0 ? 1 : totalPage;
			currentPage = currentPage > totalPage ? totalPage : currentPage;
			List<TUserPayReport> list=userPayReportService.getTUserPayReportList(year, month, name, jobnumber,organizationid,(currentPage - 1) * pageSize, pageSize);
			request.setAttribute("currentPage", currentPage);
	        request.setAttribute("totalNum", totalNum);
	        request.setAttribute("totalPage", totalPage);
			request.setAttribute("list", list);
			request.setAttribute("time", time);
		}
		return "compensation/remunerationindex";
	}
	
	
	
	//导出用户信息
	@RequestMapping("export")  
	public void exportInof(HttpServletRequest request,HttpServletResponse response) throws Exception{  
	    response.setContentType("application/vnd.ms-excel");  
	    String filename="薪酬报表.xls";
	    filename = new String(filename.getBytes(), "ISO-8859-1");
	    response.setHeader("Content-Disposition", "attachment; filename="+filename);  
	    OutputStream out = response.getOutputStream();  
	    String time=request.getParameter("time");
		String name=request.getParameter("name");
		String jobnumber=request.getParameter("jobnumber");
		int organizationid=(int) request.getSession().getAttribute("organizationid");
		int year=0;
		int month=0;
		if(time!=null&&time!=""){
			if(time.lastIndexOf("-")>-1){
				year=Integer.valueOf(time.substring(0,time.lastIndexOf("-")));
				month=Integer.valueOf(time.substring(time.lastIndexOf("-")+1, time.length()));
			}
			int pageSize = 10;
			// 获取当前页数
			int currentPage = 1;
			try {
				currentPage = new Integer(request.getParameter("currentPage"));
			} catch (Exception e) {
			}
			currentPage = currentPage <= 0 ? 1 : currentPage;
			int totalNum = userPayReportService.getTUserPayReportNum(year, month, name, jobnumber,organizationid);
			int totalPage = totalNum / pageSize;
			if (totalNum % pageSize != 0) {
				totalPage++;
			}
			totalPage = totalPage <= 0 ? 1 : totalPage;
			currentPage = currentPage > totalPage ? totalPage : currentPage;
			List<TUserPayReport> list=userPayReportService.getTUserPayReportList(year, month, name, jobnumber,organizationid,(currentPage - 1) * pageSize, pageSize);
			List<TUserPayReportList> replist=new ArrayList<TUserPayReportList>();
			for (TUserPayReport pay : list) {
				TUserPayReportList rep=new TUserPayReportList();
				rep.setUsername(pay.getUser().getName());
				rep.setYearmonth(pay.getYear()+"-"+pay.getMonth());
				rep.setTotalpayroll(pay.getTotalpayroll());
				rep.setActualbasesalary(pay.getActualbasesalary());
				rep.setYcqts(pay.getYcqts());
				rep.setAbsenteeismdays(pay.getAbsenteeismdays());
				rep.setRealsalary(pay.getRealsalary());
				rep.setLatenumber(pay.getLatenumber());
				rep.setLatetime(pay.getLatetime());
				rep.setEarlynumber(pay.getEarlynumber());
				rep.setEarlytime(pay.getEarlytime());
				rep.setLatedeductions(pay.getLatedeductions());
				rep.setEarlydeductions(pay.getEarlydeductions());
				rep.setOvertimenumber(pay.getOvertimenumber());
				rep.setOvertimemoney(pay.getOvertimemoney());
				rep.setAccumulationFund(pay.getAccumulationFund());
				rep.setSocialSecurity(pay.getSocialSecurity());
				rep.setPersonalIncomeTax(pay.getPersonalIncomeTax());
				rep.setSubsidy(pay.getSubsidy());
				rep.setOtherSubsidies(pay.getOtherSubsidies());
				rep.setAnnualBonus(pay.getAnnualBonus());
				rep.setAnnualBonusTax(pay.getAnnualBonusTax());
				rep.setTaxableSalary(pay.getTaxableSalary());
				rep.setPayroll(pay.getPayroll());
				replist.add(rep);
			}
			ExcelUtil<TUserPayReportList> t=new ExcelUtil<TUserPayReportList>();
			String [] headers={"姓名","日期","计薪总额","底薪","出勤天数","缺勤天数","出勤薪资","迟到次数","迟到分钟",
					"早退次数","早退分钟","迟到扣款","早退扣款","加班次数","加班金额","公积金","社保","个税","补贴","其他补贴",
					"年终奖","年终奖税","应税薪资","实发薪资"};  
			t.exportExcel("sheet名称", headers, replist, out, "yyyy-MM-dd HH:mm:ss");
		}
	}
	
	
	/**
	 * 查看薪酬报表信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/getUserPayReport",method=RequestMethod.GET)
	public String getUserPayReport(HttpServletRequest request, Model model){
		String id = request.getParameter("id");
		int frequency=0;//免扣次数
		int cout=0;//统计迟到次数
		int frequencyEarly=0;//免扣累计分钟数
		int earlytotalt=0;//统计早退时间
		int organizationid=(int) request.getSession().getAttribute("organizationid");
		String time="";
		double money=0;
		TUserPayReport payreport=userPayReportService.getTUserPayReportByid(id);
		if(payreport!=null){
			time+=payreport.getYear()+"-"+payreport.getMonth()+"-01";
		}else{
			request.setAttribute("msg", "获取用户信息失败！");
			return "compensation/selectremuneration";
		}
		List<TUserPay> paylist=userPayService.selectTUserPayListUserid(String.valueOf(payreport.getUserId()));
		if(paylist==null||paylist.size()==0){
			request.setAttribute("msg", "获取用户信息失败！");
			return "compensation/selectremuneration";
		}
		List<TLatedeductions> latelist=latedeductionsService.getTLatedeductionsList(organizationid);//迟到规则信息
		if(latelist!=null&&latelist.size()>0){
			frequency=latelist.get(0).getFrequency();
		}
		List<TLatedeductions> retreatlist=latedeductionsService.getTLEarlyretreatList(organizationid);//早退规则信息
		if(retreatlist!=null&&retreatlist.size()>0){
			frequencyEarly=retreatlist.get(0).getFrequency();
		}
		long starttime=DateUtil.getFirstDayOfMonth(time);
		long endtime=DateUtil.getLastDayOfMonth(time);
		List<TAttendance> attendanlist=attendanceService.getTAttendanceLatetimeList(payreport.getUserId(),starttime, endtime);//根据时间获取用户迟到信息
		List<TMaindata> maindatalist=maindataService.getAllMaindataListStatus(String.valueOf(payreport.getUserId()),"2", starttime, endtime,organizationid);//获取加班审批信息
		List<TSubsidy> sublist=subsidyService.getTSubsidyList(payreport.getUserId());//员工福利补贴信息
		List<LateBean> latebeanlist=new ArrayList<LateBean>(); //迟到
		List<EarlyBean> earlybeanlist=new ArrayList<EarlyBean>(); //早退
		List<OvertimeBean> overtimebeanlist=new ArrayList<OvertimeBean>();
		LateBean latebean=new LateBean();//迟到数据格式封装
		EarlyBean earlybean=new EarlyBean();//早退数据格式封装
		OvertimeBean overtimebean=new OvertimeBean();
		if(paylist.get(0).getStatus()==1){//白领
			for (TAttendance att : attendanlist) {
				cout=getLateBeanList(latelist, att, latebean, latebeanlist, cout, frequency);
				earlytotalt=getEarlyBeanList(retreatlist, att, earlybean, earlybeanlist, earlytotalt, frequencyEarly);//计算薪酬早退扣款信息
				String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
				for (TMaindata maindata : maindatalist) {
					if(maindata.getOvertime()!=null){
						String overStart=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
						if(createtime.equals(overStart)){//验证当前打卡日期是否和审批单日期匹配
							if(maindata.getOvertime().getType()==2){//加班
								if(maindata.getOvertime().getUnit()==3){//时单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==1){
											money+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
							}
						}
					}
				}
			}
		}else{//其他
			for (TAttendance att : attendanlist) {
				String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
				for (TMaindata maindata : maindatalist) {
					if(maindata.getOvertime()!=null){
						String overStart=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
						if(createtime.equals(overStart)){//验证当前打卡日期是否和审批单日期匹配
							if(maindata.getOvertime().getType()==2){//加班
								if(maindata.getOvertime().getUnit()==1){//吨单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==3){
											money+=getRealsalaryTon(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
								if(maindata.getOvertime().getUnit()==2){//件单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==2){
											money+=getRealsalaryPiece(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
								if(maindata.getOvertime().getUnit()==3){//时单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==1){
											money+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
							}
						}
					}
				}
			}
		}
		int overtime = payreport.getEarlytime() - frequencyEarly;
		request.setAttribute("pay", payreport);
		request.setAttribute("latebeanlist", latebeanlist);
		request.setAttribute("earlybeanlist", earlybeanlist);
		request.setAttribute("overtime", overtime);
		request.setAttribute("overtimebeanlist", overtimebeanlist);
		request.setAttribute("sublist", sublist);
		return "compensation/selectremuneration";
	}
	
	/**
	 * 封装迟到扣款对象
	 * @param latetime迟到时间
	 * @param latelist
	 * @return
	 */
	public LateBean getLateBean(LateBean latebean,int latetime,long createtime,int starminutes,
			int endminutes,double money){
		latebean=new LateBean();
		latebean.setLatetime(latetime);
		latebean.setTime(createtime);
		latebean.setStarminutes(starminutes);
		latebean.setEndminutes(endminutes);
		latebean.setMoney(money);
		return latebean;
	}
	
	/**
	 * 封装早退扣款对象
	 * @param latetime迟到时间
	 * @param latelist
	 * @return
	 */
	public EarlyBean getEarlyBean(EarlyBean earlybean,int earlyminute,long earlytime,int starminutes,
			int endminutes,double money){
		earlybean=new EarlyBean();
		earlybean.setEarlyminute(earlyminute);
		earlybean.setEarlytime(earlytime);
		earlybean.setStarminutes(starminutes);
		earlybean.setEndminutes(endminutes);
		earlybean.setMoney(money);
		return earlybean;
	}
	
	/**
	 * 封装加班金额对象
	 * @param overtimeBean
	 * @return
	 */
	public OvertimeBean getOvertimeBean(OvertimeBean overtimebean,double number,int unit,
			double money,long time){
		overtimebean=new OvertimeBean();
		overtimebean.setTime(time);
		overtimebean.setNumber(number);
		overtimebean.setUnit(unit);
		overtimebean.setMoney(money);
		return overtimebean;
	}
	
	/**
	 * 计算薪酬迟到扣款信息
	 * @param latelist 迟到规则信息
	 * @param att  用户迟到信息
	 * @param latebean 迟到扣款对象
	 * @param latebeanlist 迟到扣款对象集合
	 * @param cout 统计迟到次数
	 * @param frequency 免扣次数
	 * @return
	 */
	public int getLateBeanList(List<TLatedeductions> latelist,TAttendance att,LateBean latebean,
			List<LateBean> latebeanlist,int cout,int frequency){
		if(att.getResults1()>0){
			cout++;
			if(cout>frequency){
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults1()>=late.getStarminutes()&&att.getResults1()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults1(), att.getStarttime1(), late.getStarminutes(),
								late.getEndminutes(), late.getMoney());
						latebeanlist.add(latebean);
					}
				}
			}else{
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults1()>=late.getStarminutes()&&att.getResults1()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults1(), att.getStarttime1(), late.getStarminutes(),
								late.getEndminutes(), 0);
						latebeanlist.add(latebean);
					}
				}
			}
		}
		if(att.getResults3()>0){
			cout++;
			if(cout>frequency){
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults3()>=late.getStarminutes()&&att.getResults3()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults3(), att.getStarttime2(), late.getStarminutes(),
								late.getEndminutes(), late.getMoney());
						latebeanlist.add(latebean);
					}
				}
			}else{
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults3()>=late.getStarminutes()&&att.getResults3()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults3(), att.getStarttime2(), late.getStarminutes(),
								late.getEndminutes(), 0);
						latebeanlist.add(latebean);
					}
				}
			}
		}
		if(att.getResults5()>0){
			cout++;
			if(cout>frequency){
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults5()>=late.getStarminutes()&&att.getResults5()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults5(), att.getStarttime3(), late.getStarminutes(),
								late.getEndminutes(), late.getMoney());
						latebeanlist.add(latebean);
					}
				}
			}else{
				for (TLatedeductions late : latelist) {
					latebean=new LateBean();
					if(att.getResults5()>=late.getStarminutes()&&att.getResults5()<=late.getEndminutes()){
						latebean=getLateBean(latebean,att.getResults5(), att.getStarttime3(), late.getStarminutes(),
								late.getEndminutes(), 0);
						latebeanlist.add(latebean);
					}
				}
			}
		}
		return cout;
	}
	
	/**
	 * 计算薪酬早退扣款信息
	 * @param earlylist 早退规则信息
	 * @param att 早退迟到信息
	 * @param earlybean 早退扣款对象
	 * @param earlybeanlist 早退扣款对象集合
	 * @param earlytotalt 统计早退时间
	 * @param frequencyEarly 免扣累计分钟
	 * @return
	 */
	public int getEarlyBeanList(List<TLatedeductions> earlylist,TAttendance att,EarlyBean earlybean,
			List<EarlyBean> earlybeanlist,int earlytotalt,int frequencyEarly){
		if(att.getResults2()>0){
			earlytotalt+=att.getEarlytime();//累计早退分钟
			if(earlytotalt>frequencyEarly){
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults2()>=early.getStarminutes()&&att.getResults2()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults2(), att.getEndtime1(), early.getStarminutes(),
								early.getEndminutes(), early.getMoney());
						earlybeanlist.add(earlybean);
					}
				}
			}else{
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults2()>=early.getStarminutes()&&att.getResults1()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults2(), att.getEndtime1(), early.getStarminutes(),
								early.getEndminutes(), 0);
						earlybeanlist.add(earlybean);
					}
				}
			}
		}
		if(att.getResults4()>0){
			earlytotalt+=att.getEarlytime();
			if(earlytotalt>frequencyEarly){
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults4()>=early.getStarminutes()&&att.getResults4()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults4(), att.getEndtime2(), early.getStarminutes(),
								early.getEndminutes(), early.getMoney());
						earlybeanlist.add(earlybean);
					}
				}
			}else{
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults4()>=early.getStarminutes()&&att.getResults4()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults4(), att.getEndtime2(), early.getStarminutes(),
								early.getEndminutes(), 0);
						earlybeanlist.add(earlybean);
					}
				}
			}
		}
		if(att.getResults6()>0){
			earlytotalt+=att.getEarlytime();
			if(earlytotalt>frequencyEarly){
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults6()>=early.getStarminutes()&&att.getResults6()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults6(), att.getEndtime3(), early.getStarminutes(),
								early.getEndminutes(), early.getMoney());
						earlybeanlist.add(earlybean);
					}
				}
			}else{
				for (TLatedeductions early : earlylist) {
					earlybean=new EarlyBean();
					if(att.getResults6()>=early.getStarminutes()&&att.getResults6()<=early.getEndminutes()){
						earlybean=getEarlyBean(earlybean,att.getResults6(), att.getEndtime3(), early.getStarminutes(),
								early.getEndminutes(), 0);
						earlybeanlist.add(earlybean);
					}
				}
			}
		}
		return earlytotalt;
	}
	
	
	/**
	 * 生成薪酬报表信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/insert",method=RequestMethod.GET)
	public String insert(HttpServletRequest request, Model model){
		String time=request.getParameter("time");
		request.setAttribute("time", time);
		if(time!=null&&time!=""){
			int year=0;
			int month=0;
			double realsalary=0;//实际薪资
			int latenumber=0;//迟到次数
			int latetime=0;//迟到分钟
			double latedeductions=0;//迟到扣款
			int frequency=0;//免扣次数
			int cout=0;//统计迟到次数
			int earlynumber=0;//早退次数
			int earlytime=0;//早退分钟
			double earlydeductions=0;//早退扣款
			int frequencyEarly = 0;//免扣累计分钟
			int totalt=0;//统计早退次数
			int overtimenumber=0;//加班次数
			double overtimemoney=0;//加班金额
			double money=0;//金额
			String taxableTime="";//应税时间
			int organizationid=(int) request.getSession().getAttribute("organizationid");
			if(time.lastIndexOf("-")>-1){
				year=Integer.valueOf(time.substring(0,time.lastIndexOf("-")));
				month=Integer.valueOf(time.substring(time.lastIndexOf("-")+1, time.length()));
			}
			time+="-01";
			if(month>=10){
				taxableTime=year+"-"+month;
			}else{
				taxableTime=year+"-0"+month;
			}
			
			List<TLatedeductions> latelist=latedeductionsService.getTLatedeductionsList(organizationid);//迟到规则信息
			if(latelist!=null&&latelist.size()>0){
				frequency=latelist.get(0).getFrequency();
			}
			
			List<TLatedeductions> retreatlist=latedeductionsService.getTLEarlyretreatList(organizationid);//早退规则信息
			if(retreatlist!=null&&retreatlist.size()>0){
				frequencyEarly=retreatlist.get(0).getFrequency();
			}
			
			long starttime=DateUtil.getFirstDayOfMonth(time);
			long endtime=DateUtil.getLastDayOfMonth(time);
			List<UserBean> userlist=userBeanService.getUserBeanList(starttime, endtime,taxableTime,organizationid);//获取用户信息、考勤信息、薪酬信息、年终奖信息、员工补贴信息
			List<TMaindata> maindatalist=maindataService.getAllMaindataListStatus(null,"2", starttime, endtime,organizationid);//获取加班审批信息
			int totalNum = userPayReportService.getTUserPayReportNum(year, month, null, null,organizationid);
			List<TUserPayReport> payreportlist=new ArrayList<TUserPayReport>();
			List<TIndividualTaxFormula> taxformulalist=individualTaxFormulaService.selectTIndividualTaxFormulaList(organizationid);//获取所有个税公式信息
			if(totalNum!=0){//验证薪酬报表是否存在
				userPayReportService.deleteTUserPayReportList(year, month);
				getSalarystatistics(userlist, latelist, payreportlist,maindatalist,taxformulalist,latenumber, latetime, 
						realsalary, latedeductions, frequency, cout, year, month,overtimenumber,overtimemoney,
						money,organizationid,
						retreatlist,frequencyEarly,earlynumber,earlytime,earlydeductions,totalt);
			}else{
				getSalarystatistics(userlist, latelist, payreportlist,maindatalist,taxformulalist,latenumber, latetime, 
						realsalary, latedeductions, frequency, cout, year, month,overtimenumber,overtimemoney,
						money,organizationid,
						retreatlist,frequencyEarly,earlynumber,earlytime,earlydeductions,totalt);
			}
			if(payreportlist.size()>0){
				userPayReportService.insertTUserPayReportList(payreportlist);
			}
			request.setAttribute("msg", "薪酬报表生成完成");
		}else{
			request.setAttribute("msg", "请选年月生成薪酬报表");
		}
		return "compensation/remunerationindex";
	}
	
	/**
	 * 计算迟到扣款金额
	 * @param latetime迟到时间
	 * @param latelist
	 * @return
	 */
	public double getTLatedeductions(int latetime,List<TLatedeductions> latelist){
		for (TLatedeductions late : latelist) {
			if(latetime>=late.getStarminutes()&&latetime<=late.getEndminutes()){
				return late.getMoney();
			}
		}
		return 0;
	}
	
	/**
	 * 计算早退扣款金额
	 * @param earlytime 早退时间
	 * @param retreatlist 早退规则 
	 * @return
	 */
	public double getEarlydeductions(int earlytime,List<TLatedeductions> retreatlist){
		for (TLatedeductions early : retreatlist) {
			if(earlytime>=early.getStarminutes()&&earlytime<=early.getEndminutes()){
				return early.getMoney();
			}
		}
		return 0;
	}
	
	
	/**
	 * 根据时单位计薪(分)
	 * @param pay
	 * @param att
	 * @return
	 */
	public double getRealsalaryBranch(TUserPay pay,AttendanceBean att){
		double time=att.getWorkingtime();
		double money=0;
		money=time/60*pay.getSalary();
		return money;
	}
	/**
	 * 根据时单位计薪(时)
	 * @param pay
	 * @param 
	 * @return
	 */
	public double getRealsalaryTime(TUserPay pay,double time){
		double money=0;
		money=time*pay.getSalary();
		return money;
	}
	/**
	 * 根据件单位计薪(件)
	 * @param pay
	 * @param 
	 * @return
	 */
	public double getRealsalaryPiece(TUserPay pay,double piece){
		double money=0;
		money=piece*pay.getSalary();
		return money;
	}
	/**
	 * 根据吨单位计薪(吨)
	 * @param pay
	 * @param 
	 * @return
	 */
	public double getRealsalaryTon(TUserPay pay,double ton){
		double money=0;
		money=ton*pay.getSalary();
		return money;
	}
	
	/**
	 * 计算其他补贴金额
	 * @param user
	 * @param payreport
	 * @param realsalary
	 */
	public void getOtherSubsidies(UserBean user,TUserPayReport payreport,double realsalary){
		double otherSubsidies=0;//其他补贴
		if(user.getPay().get(0).getBasicStatus()==1){//计算其他补贴金额
			if(user.getPay().get(0).getBasicSalary()<realsalary){
				otherSubsidies=(realsalary*100-user.getPay().get(0).getBasicSalary()*100)/100;
			}
		}
		payreport.setOtherSubsidies(otherSubsidies);
	}
	
	/**
	 * 计算补贴金额
	 * @param user
	 * @return
	 */
	public void getSubsidy(UserBean user,TUserPayReport payreport){
		double subsidy=0;//补贴
		for (TSubsidy sub : user.getSublist()) {//计算补贴
			subsidy+=sub.getMoney();
		}
		payreport.setSubsidy(subsidy);
	}
	
	/**
	 * 年终奖计算
	 * @param user
	 * @param realsalary
	 * @param payreport
	 * @param taxformulalist
	 */
	public void getAnnualbonus(UserBean user,double realsalary,TUserPayReport payreport,
			List<TIndividualTaxFormula> taxformulalist){
		double annualbonus=0;//年终奖
		double annualbonustax=0;//年终奖税
		double average=0;//年终奖12个月平均值
		if(user.getBonuslist()!=null&&user.getBonuslist().size()>0){//计算年终奖
			annualbonus=user.getBonuslist().get(0).getMoney();
			if(realsalary>=3500){
				average=annualbonus/12;
			}else{
				average=(annualbonus-(3500-realsalary))/12;
			}
			for (TIndividualTaxFormula  tax : taxformulalist) {//匹配税率
				if(tax.getTaxablestart()<=average&&average<tax.getTaxableend()){
					//年终奖交税=年终奖*税率-速算扣除数
					annualbonustax=annualbonus*100*tax.getTaxrate()/100-tax.getDeductions();
				}
			}
		}
		payreport.setAnnualBonus(annualbonus);
		payreport.setAnnualBonusTax(annualbonustax);
	}
	
	/**
	 * 计算个税
	 * @param realsalary
	 * @param payreport
	 * @param taxformulalist
	 */
	public void getPersonalincometax(double realsalary,TUserPayReport payreport,
			List<TIndividualTaxFormula> taxformulalist){
		double personalIncomeTax=0;//个税
		double money=0;//应税薪资
		money=realsalary-3500;//扣除3500免税薪资
		for (TIndividualTaxFormula  tax : taxformulalist) {//计算个税
			if(tax.getTaxablestart()<=money&&money<tax.getTaxableend()){
				//个人所得税=应税薪资*税率-速算扣除数
				personalIncomeTax=money*100*tax.getTaxrate()/100-tax.getDeductions();
				return;
			}
		}
		if(money>0){
			payreport.setTaxableSalary(money);
		}else{
			payreport.setTaxableSalary(0);
		}
		payreport.setPersonalIncomeTax(personalIncomeTax);
	}
	
	/**
	 * 薪资结算
	 * @param payreport 用户薪酬报表
	 * @param latenumber 迟到次数
	 * @param latetime 迟到分钟
	 * @param latedeductions 迟到扣款
	 * @param earlynumber 早退次数
	 * @param earlytime 早退分钟
	 * @param earlydeductions 早退扣款
	 * @param overtimemoney 加班金额
	 * @param overtimenumber 加班次数
	 * @param user 获取用户信息、考勤信息、薪酬信息、年终奖信息、员工补贴信息
	 * @param realsalary 实际薪资
	 * @param payreportlist 用户薪酬报表集合
	 * @param taxformulalist 个税公式信息
	 */
	public void getSettlement(TUserPayReport payreport,int latenumber,int latetime,double latedeductions,double overtimemoney,
			int overtimenumber,UserBean user,double realsalary,List<TUserPayReport> payreportlist,
			List<TIndividualTaxFormula> taxformulalist,
			int earlynumber,int earlytime,double earlydeductions){
		double accumulationFund=0;//公积金
		double payroll=0;//实发薪资
		double totalpayroll=0;//总额
		BigDecimal	formatting=new	BigDecimal(realsalary);  
		realsalary=formatting.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
		payreport.setLatenumber(latenumber);
		payreport.setLatetime(latetime);
		payreport.setLatedeductions(latedeductions);
		realsalary=((realsalary*100)-(latedeductions*100))/100;//扣除迟到扣款
		payreport.setEarlynumber(earlynumber);
		payreport.setEarlytime(earlytime);
		payreport.setEarlydeductions(earlydeductions);
		realsalary=((realsalary*100)-(earlydeductions*100))/100;//扣除早退扣款
		payreport.setOvertimemoney(overtimemoney);
		payreport.setOvertimenumber(overtimenumber);
		if(user.getAttlist()!=null){
			payreport.setYcqts(user.getAttlist().size());
			payreport.setAbsenteeismdays(user.getPay().get(0).getDays()-user.getAttlist().size());
		}else{
			payreport.setYcqts(0);
			payreport.setAbsenteeismdays(user.getPay().get(0).getDays());
		}
		accumulationFund=user.getPay().get(0).getCardinalNumber()*user.getPay().get(0).getRadix()/100;//计算公积金
		//工资=工资-公积金
		realsalary=(realsalary*100-accumulationFund*100)/100;//扣除公积金
		payreport.setAccumulationFund(accumulationFund);
		getSubsidy(user, payreport);//计算补贴金额
		//工资=工资-补贴金额
		realsalary=(realsalary*100-payreport.getSubsidy()*100)/100;//扣除补贴金额
		getOtherSubsidies(user, payreport, realsalary);//计算其他补贴金额
		//工资=工资-其他补贴金额
		realsalary=(realsalary*100-payreport.getOtherSubsidies()*100)/100;//扣除其他补贴金额
		payreport.setRealsalary(realsalary);	
		realsalary+=payreport.getOvertimemoney();//加加班
		/*List<Map<String, Object>> performances = performanceService.getPerformanceList(user.getId());
		List<TUserPay> ls = user.getPay();*/
		payreport.setRaisewages(0);
		getAnnualbonus(user, realsalary, payreport, taxformulalist);//计算年终奖
		getPersonalincometax(realsalary, payreport, taxformulalist);//计算个税
		//实发薪资=工资 - 个人所得税  + 年终奖 - 年终奖应税 + 补贴 + 其他补贴
		payroll=realsalary-payreport.getPersonalIncomeTax()+payreport.getAnnualBonus()
				-payreport.getAnnualBonusTax()+payreport.getSubsidy()+payreport.getOtherSubsidies();
		payreport.setPayroll(payroll);
		//实发薪资=工资 + 个人所得税 + 加班补贴 + 年终奖 + 年终奖应税 + 补贴 + 其他补贴 + 公积金 + 迟到扣款
		totalpayroll=realsalary+payreport.getPersonalIncomeTax()+payreport.getOvertimemoney()+payreport.getAnnualBonus()
				+payreport.getAnnualBonusTax()+payreport.getSubsidy()+payreport.getOtherSubsidies()+payreport.getAccumulationFund()
				+payreport.getLatedeductions();
		payreport.setTotalpayroll(totalpayroll);
		payreportlist.add(payreport);
	}
	
	
	/**
	 * 薪酬统计方法
	 * @param userlist 获取用户信息、考勤信息、薪酬信息、年终奖信息、员工补贴信息
	 * @param latelist 迟到规则信息
	 * @param retreatlist 早退规则信息
	 * @param payreportlist 用户薪酬报表集合
	 * @param maindatalist 加班审批信息
	 * @param taxformulalist 个税公式信息
 	 * @param latenumber 迟到次数
	 * @param latetime 迟到分钟
	 * @param realsalary 实际薪资
	 * @param latedeductions 迟到扣款
	 * @param frequency 免扣次数
	 * @param cout 统计迟到次数
	 * @param earlynumber 早退次数
	 * @param earlytime 早退分钟
	 * @param earlydeductions 早退扣款
	 * @param frequencyEarly 免扣累计分钟
	 * @param totalt 累计早退次数
	 * @param year 年份
	 * @param month 月份
	 * @param overtimenumber 加班次数
	 * @param overtimemoney 加班金额
	 * @param money 金额
	 * @param organizationid 商户id
	 */
	public void getSalarystatistics(List<UserBean> userlist,
			List<TLatedeductions> latelist,List<TUserPayReport> payreportlist,
			List<TMaindata> maindatalist,List<TIndividualTaxFormula> taxformulalist,
			int latenumber,int latetime,double realsalary,
			double latedeductions,int frequency,int cout,int year,int month,
			int overtimenumber,double overtimemoney,double money,
			int organizationid,
			List<TLatedeductions> retreatlist,int frequencyEarly,int earlynumber,int earlytime,
			double earlydeductions,int totalt){
		TUserPayReport payreport=null;
		for (UserBean user : userlist) {
			realsalary=0;
			payreport=new TUserPayReport();
			payreport.setOrganizationId(organizationid);
			payreport.setYear(Integer.valueOf(year));
			payreport.setMonth(Integer.valueOf(month));
			payreport.setUserId(user.getId());
			if(user.getPay()!=null&&user.getPay().size()>0){
				payreport.setActualbasesalary(user.getPay().get(0).getBasesalary());
				if(user.getPay().get(0).getStatus()==1){//白领
					for (TUserPay pay : user.getPay()) {
						if(pay.getType()==1){//时
							for (AttendanceBean att : user.getAttlist()) {
								if(att.getResults1()>0){
									latenumber++;
									cout++;//迟到次数
									if(cout>frequency){
										latedeductions+=getTLatedeductions(att.getResults1(), latelist);
									}
								}
								if(att.getResults3()>0){
									latenumber++;
									cout++;
									if(cout>frequency){
										latedeductions+=getTLatedeductions(att.getResults3(), latelist);
									}
								}
								if(att.getResults5()>0){
									latenumber++;
									cout++;
									if(cout>frequency){
										latedeductions+=getTLatedeductions(att.getResults5(), latelist);
									}
								}
								if(att.getResults2()>0){//早退
									earlynumber++;//早退次数
									/*earlytime+=att.getResults2();//累计早退分钟
									//totalt++;//累计早退次数
									if(earlytime>frequencyEarly){
										earlydeductions+=getEarlydeductions(att.getResults2(), retreatlist);
									}*/
								}
								if(att.getResults4()>0){
									earlynumber++;
								}
								if(att.getResults6()>0){
									earlynumber++;
								}
								earlytime = att.getEarlytime();//总早退时间
								if(earlytime>frequencyEarly){
									int earlyretreattime = att.getEarlytime() - frequencyEarly;//超过免扣分钟的时间
									earlydeductions+=getEarlydeductions(earlyretreattime, retreatlist);
								}
								
								latetime+=att.getLatetime();//迟到分钟
								//earlytime+=att.getEarlytime();//早退分钟
								realsalary+=getRealsalaryBranch(pay, att);
								String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
								for (TMaindata maindata : maindatalist) {
									if(maindata.getUserid()==user.getId()){//匹配获取该用户审批单
										if(maindata.getOvertime()!=null){
											if(maindata.getOvertime().getType()!=null){
												if(maindata.getOvertime().getType()==2){//加班
													String starttime=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
													if(createtime.equals(starttime)){//验证当前打卡日期是否和审批单日期匹配
														if(maindata.getOvertime().getUnit()!=null){
															if(maindata.getOvertime().getUnit()==3){//时单位审批单
																overtimenumber++;
																money=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
																overtimemoney+=money;
															}
														}
													}
												}
											}
										}
									}
								}
							}
							getSettlement(payreport, latenumber, latetime, latedeductions, overtimemoney, overtimenumber, user, 
									realsalary, payreportlist, taxformulalist,
									earlynumber,earlytime,earlydeductions);
						}
					}
				}else{//其他
					for (AttendanceBean att : user.getAttlist()) {
						String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
						for (TMaindata maindata : maindatalist) {//遍历审批单
							if(maindata.getUserid()==user.getId()){//匹配获取该用户审批单
								if(maindata.getOvertime()!=null){
									String starttime=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
									if(createtime.equals(starttime)){//验证当前打卡日期是否和审批单日期匹配
										if(maindata.getOvertime().getUnit()!=null&&maindata.getOvertime().getUnit()==1){//吨单位审批单
											for (TUserPay pay : user.getPay()) {
												if(pay.getType()==3){
													if(maindata.getOvertime().getType()!=null&&maindata.getOvertime().getType()==2){//加班
														overtimenumber++;
														overtimemoney+=getRealsalaryTon(pay, maindata.getOvertime().getNumber());
													}else{
														realsalary+=getRealsalaryTon(pay, maindata.getOvertime().getNumber());
													}
												
												}
											}
										}
										if(maindata.getOvertime().getUnit()==2){//件单位审批单
											for (TUserPay pay : user.getPay()) {
												if(pay.getType()==2){
													if(maindata.getOvertime().getType()!=null&&maindata.getOvertime().getType()==2){//加班
														overtimenumber++;
														overtimemoney+=getRealsalaryPiece(pay, maindata.getOvertime().getNumber());
													}else{
														realsalary+=getRealsalaryPiece(pay, maindata.getOvertime().getNumber());
													}
												}
											}
										}
										if(maindata.getOvertime().getUnit()!=null&&maindata.getOvertime().getUnit()==3){//时单位审批单
											for (TUserPay pay : user.getPay()) {
												if(pay.getType()==1){
													if(maindata.getOvertime().getType()==2){//加班
														overtimenumber++;
														overtimemoney+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
													}else{
														realsalary+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
													}
												}
											}
										}
									}
								}
							}
						}
						if(att.getResults1()>0){
							latenumber++;
						}
						if(att.getResults3()>0){
							latenumber++;
						}
						if(att.getResults5()>0){
							latenumber++;
						}
						latetime+=att.getLatetime();
						
						if(att.getResults2()>0){
							earlynumber++;
						}
						if(att.getResults4()>0){
							earlynumber++;
						}
						if(att.getResults6()>0){
							earlynumber++;
						}
						earlytime+=att.getEarlytime();
					}
					getSettlement(payreport, latenumber, latetime, latedeductions, overtimemoney, overtimenumber, user, 
							realsalary, payreportlist, taxformulalist,
							earlynumber,earlytime,earlydeductions);
				}
			}
		}
	}
	
	
	
	
	/**
	 * APP查看薪酬报表信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/getUserPayReportApp", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getUserPayReportApp(HttpServletRequest request, Model model) {
		String msg=null;
		JSONObject jsonObject = null;
//		String sign =null;//身份认证
		String id =null;//用户id
		int frequency=0;//免扣次数
		int frequencyEarly = 0;//免扣累计分钟
		int cout=0;//统计迟到次数
		int earlytotalt=0;//统计早退时间
		String time="";
		double money=0;
		int organizationid=0;
		String json = request.getParameter("json");
		jsonObject = JSONObject.fromObject(json);
		try{
			id =jsonObject.getString("userid");
//			sign =jsonObject.getString("sign");
			time =jsonObject.getString("time");
			organizationid =jsonObject.getInt("organizationid");
		}catch(Exception e){
			msg="{\"code\":\"9002\",\"msg\":\"参数有误"+e.getMessage().replaceAll("\"", "")+"\"}";
            return msg;
		}
		String[] date=null;
		if(time.lastIndexOf("-")>-1){
			date=time.split("-");
		}
		TUser user=userService.selectTUserId(id);
//		if (user == null) {
//			msg="{\"code\":\"3\",\"msg\":\"用户信息有误\"}";
//			return msg;
//		}
//		boolean judge=IdentityController.authentication(user, IdentityController.GETUSERPAYREPORTAPP, sign);
//		if(!judge){
//			msg="{\"code\":\"3\",\"msg\":\"用户身份信息有误\"}";
//			return msg;
//		}
		TUserPayReport payreport=null;
		if(date.length==2){
			payreport=userPayReportService.getTUserPayReportByUserid(id,date[0].toString(),date[1].toString());
			if(payreport==null){
				msg="{\"code\":\"2\",\"msg\":\"未获取到本月用户薪酬信息\"}";
				return msg;
			}
		}else{
			msg="{\"code\":\"2\",\"msg\":\"未获取到本月用户薪酬信息\"}";
			return msg;
		}
		List<TUserPay> paylist=userPayService.selectTUserPayListUserid(String.valueOf(payreport.getUserId()));
		if(paylist==null||paylist.size()==0){
			msg="{\"code\":\"2\",\"msg\":\"获取用户薪酬信息失败\"}";
			return msg;
		}
		
		List<TLatedeductions> latelist=latedeductionsService.getTLatedeductionsList(organizationid);//迟到规则信息
		if(latelist!=null&&latelist.size()>0){
			frequency=latelist.get(0).getFrequency();
		}
		List<TLatedeductions> retreatlist=latedeductionsService.getTLEarlyretreatList(organizationid);//早退规则信息
		if(retreatlist!=null&&retreatlist.size()>0){
			frequencyEarly=retreatlist.get(0).getFrequency();
		}
		
		time+="-01";
		long starttime=DateUtil.getFirstDayOfMonth(time);
		long endtime=DateUtil.getLastDayOfMonth(time);
		List<TAttendance> attendanlist=attendanceService.getTAttendanceLatetimeList(payreport.getUserId(),starttime, endtime);//根据时间获取用户迟到信息
		List<TMaindata> maindatalist=maindataService.getAllMaindataListStatus(String.valueOf(payreport.getUserId()),"2", starttime, endtime,organizationid);//获取加班审批信息
		List<LateBean> latebeanlist=new ArrayList<LateBean>(); //迟到
		List<EarlyBean> earlybeanlist=new ArrayList<EarlyBean>(); //早退
		
		List<OvertimeBean> overtimebeanlist=new ArrayList<OvertimeBean>();
		List<TSubsidy> sublist=subsidyService.getTSubsidyList(payreport.getUserId());//员工福利补贴信息
		LateBean latebean=new LateBean();//迟到数据格式封装
		EarlyBean earlybean=new EarlyBean();//早退数据格式封装
		
		OvertimeBean overtimebean=new OvertimeBean();
		Map<String, Object> datemap=new HashMap<String, Object>();
		if(paylist.get(0).getStatus()==1){//白领
			for (TAttendance att : attendanlist) {
				cout=getLateBeanList(latelist, att, latebean, latebeanlist, cout, frequency);//计算薪酬迟到扣款信息
				earlytotalt=getEarlyBeanList(retreatlist, att, earlybean, earlybeanlist, earlytotalt, frequencyEarly);//计算薪酬早退扣款信息
				String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
				for (TMaindata maindata : maindatalist) {
					if(maindata.getOvertime()!=null&&maindata.getOvertime().getStarttime()!=null){
						String overStart=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
						if(createtime.equals(overStart)){//验证当前打卡日期是否和审批单日期匹配
							if(maindata.getOvertime().getType()==2){//加班
								if(maindata.getOvertime().getUnit()==3){//时单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==1){
											money+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
							}
						}
					}
				}
			}
		}else{//其他
			for (TAttendance att : attendanlist) {
				String createtime=DateUtil.getStringFormat(att.getCreatetime());//验证加班日期
				for (TMaindata maindata : maindatalist) {
					if(maindata.getOvertime()!=null&&maindata.getOvertime().getStarttime()!=null){
						String overStart=DateUtil.getStringFormat(maindata.getOvertime().getStarttime());
						if(createtime.equals(overStart)){//验证当前打卡日期是否和审批单日期匹配
							if(maindata.getOvertime().getType()==2){//加班
								if(maindata.getOvertime().getUnit()==1){//吨单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==3){
											money+=getRealsalaryTon(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
								if(maindata.getOvertime().getUnit()==2){//件单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==2){
											money+=getRealsalaryPiece(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
								if(maindata.getOvertime().getUnit()==3){//时单位审批单
									overtimebean=new OvertimeBean();
									money=0;
									for (TUserPay pay : paylist) {
										if(pay.getType()==1){
											money+=getRealsalaryTime(pay, maindata.getOvertime().getNumber());
										}
									}
									overtimebean=getOvertimeBean(overtimebean, maindata.getOvertime().getNumber(),
											maindata.getOvertime().getUnit(), money, maindata.getOvertime().getCreatetime());
									overtimebeanlist.add(overtimebean);
								}
							}
						}
					}
				}
			}
		}
		UserPayReportAppBean appbean=new UserPayReportAppBean();
		try {
			BeanUtils.copyProperties(appbean,payreport);
		} catch (IllegalAccessException | InvocationTargetException e) {
			msg="{\"code\":\"2\",\"msg\":\"获取用户薪酬信息失败\"}";
			return msg;
		}
		appbean.setName(user.getName());
		appbean.setLatelist(latebeanlist);//迟到记录对象
		//appbean.setEarlylist(earlybeanlist);//早退记录对象
		appbean.setOvertimelist(overtimebeanlist);
		appbean.setSubsidylist(sublist);
		datemap.put("cout", cout);//迟到次数
		datemap.put("earlytotalt", earlytotalt);//累计早退时间
		datemap.put("code", "1");
		datemap.put("data", appbean);
		JSONObject jsons = JSONObject.fromObject(datemap);
		msg=jsons.toString();
		return msg;
	}
}
